
import com.eso.frame.cache.ICache
import com.eso.haBank.domain.Customization
import com.eso.project.AppGlobal

class AppGlobalFilters {

    ICache appGlobalCache;

    def filters = {

        def expectControllers = ['auth', 'home'];
        def reWriteActions = ['index', 'list', 'search'];

        allRewritePageSize(controller: '*', action: '*') {
            before = {
                if (!expectControllers.contains(controllerName) && reWriteActions.contains(actionName)) {
                    Customization pageSizeCustomization = (Customization) appGlobalCache.get(AppGlobal.CUSTOMIZE.PAGE_SIZE);
                    try {
                        params.max = Integer.parseInt(pageSizeCustomization.customizeValue);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                return true;
            }
            after = {
                return true;
            }
            afterView = {
                return true;
            }
        }
    }
}
